﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcEngine.Mvc.Models;
using MvcEngine.HtmlText.Models.Entities;
using MvcEngine.Core.Utils;
using MvcEngine.HtmlText.Repositories;
using MvcEngine.Core;
using MvcEngine.Core.Extensions;
using MvcEngine.Core.Pagination;

namespace MvcEngine.HtmlText.Managers
{
    public class HtmlTextManager : IHtmlTextManager
    {
        private readonly IHtmlTextRepository textRepository = null;

        public HtmlTextManager(IHtmlTextRepository textRepository)
        {
            this.textRepository = textRepository;
        }

        public static IHtmlTextManager Current
        {
            get { return IoC.Resolve<IHtmlTextManager>(); }
        }

        public IPagination<HtmlTextItem> GetTexts(int pageNumber, int pageSize)
        {
            return CacheManager.Current.FromCache(string.Format(HtmlTextCacheKeys.Paging, SiteContext.Current.Site.Id, pageNumber, pageSize), HtmlTextCacheKeys.Category,
                () => textRepository.GetAll(SiteContext.Current.Site.Id, pageNumber, pageSize));
        }
    }
}
